/**
 * <b>项目名：</b>hclv-web<br/>  
 * <b>包名：</b>com.flea.hclv.service.impl<br/>  
 * <b>文件名：</b>HotelPolicyServiceImpl.java<br/>  
 * <b>版本信息：</b>1.0<br/>  
 * <b>日期：</b>2018年9月16日 下午7:19:49<br/>  
 * <b>COPYRIGHT 2010-2012 ALL RIGHTS RESERVED 虫子科技</b>-版权所有<br/>
 */
package com.flea.hclv.service.impl;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.flea.hclv.model.dao.HAddressMapper;
import com.flea.hclv.model.dao.HotelPolicyMapper;
import com.flea.hclv.model.entity.HAddress;
import com.flea.hclv.model.entity.HotelPolicy;
import com.flea.hclv.service.HotelPolicyService;
import com.flea.system.base.util.StringUtil;
import com.flea.system.bean.FleaPage;
import com.flea.system.utils.FleaStringUtils;

/**
 * @description
 * @createTime 2018年9月16日 下午7:19:49
 * @modifyTime 
 * @author myflea@163.com
 * @version 1.0
 */
@Service("hotelPolicyService")
public class HotelPolicyServiceImpl implements HotelPolicyService {
	@Autowired
	private HotelPolicyMapper hotelPolicyMapper;
	
	@Autowired
	private HAddressMapper addressMapper;
	@Override
	public boolean saveOrUpdate(String userId, HotelPolicy hotelPolicy) {
	/*	OrgDept org =	FleaOrgUtils.getCurrentUserDept(userId);*/
		String hpid = hotelPolicy.getId();
		hotelPolicy.setModifyUser(userId);
		int result = 0;
		
		if(StringUtil.isEmpty(hpid)){
			hotelPolicy.setId(FleaStringUtils.getGenerateUUID());
			hotelPolicy.setCreateUser(userId);
		
			result = hotelPolicyMapper.insertSelective(hotelPolicy);
			
		}else{
			
			result = hotelPolicyMapper.updateByPrimaryKeySelective(hotelPolicy);
		}
		
		
		return result>0;
	}
	@Override
	public FleaPage<HotelPolicy> findForGird(String queryName, String queryLevel,
			String queryProvince, String queryCity, String queryZone,
			int curPage, int pageSize) {
		RowBounds rowBounds = new RowBounds(curPage, pageSize);
		List<HotelPolicy> pageData = hotelPolicyMapper.selectPagings(rowBounds);
		FleaPage<HotelPolicy> page = new FleaPage<HotelPolicy>(pageData);
		return page;
	}
	@Override
	public FleaPage<HotelPolicy> findForGirdByOrgId(String queryName,
			String queryLevel, String queryProvince, String queryCity,
			String queryZone, int curPage, int pageSize, String orgId) {
		RowBounds rowBounds = new RowBounds(curPage, pageSize);
		
		List<HAddress> address = addressMapper.selectByParams(queryProvince,queryCity,queryZone);
		List<HotelPolicy> pageData = hotelPolicyMapper.selectPagingsParams(rowBounds,orgId,queryName,queryLevel,address);
		FleaPage<HotelPolicy> page = new FleaPage<HotelPolicy>(pageData);
		return page;

	}
	@Override
	public boolean deleteByIds(String ids, String userId) {
		List<String>  idsArray = JSON.parseArray(ids, String.class);
	
		int result = hotelPolicyMapper.deleteByPrimaryKeys(idsArray);
		return result == idsArray.size() && result > 0;
		
	}

}
